//
//  customView.m
//  Edu_iOS2018
//
//  Created by apple on 2018/1/19.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#import "ECTipCustomView.h"
#import "ZJAnimationPopView.h"

@interface ECTipCustomView(){
    ///蒙版图层view
    ZJAnimationPopView *popView;
    ///中部底层view
    UIView *baseView;
    ///上部背景图
    UIImageView *topImageView;
}

@end

@implementation ECTipCustomView

-(void)showTipviewWithTpe:(TipType)tiptype andIndexPath:(NSInteger)row{
    // 1.Get custom view【获取自定义控件】
    baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kProportion_Width(750), kProportion_Height(940))];
    baseView.backgroundColor = [UIColor whiteColor];
    baseView.layer.masksToBounds = YES;
    baseView.layer.cornerRadius = 3.f;
    
    NSString *nameStr;
    switch (tiptype) {
        case tipTypeOfCancelOrder:
            nameStr = @"Mine_tipImage_cancelOrder";
            break;
        case tipTypeOfCancelFavorite:
            nameStr = @"Mine_tipImage_cancelFav";
            break;
        case tipTypeOfFeedback:
            nameStr = @"Mine_tipImage_feedback";
            break;
        default:
            break;
    }
    topImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, baseView.mj_w, kProportion_Height(430))];
    [baseView addSubview:topImageView];
    topImageView.image = [UIImage imageNamed:nameStr];//根据不同类别设置不同上部图片
    
    [baseView updateConstraintsIfNeeded];
    
    if (tiptype == tipTypeOfFeedback) {//意见反馈
        
    }else{// 取消订单/取消收藏
        
        [self createUIWithTip:tiptype andRow:(NSInteger)row];
    
    }
    
    popView = [[ZJAnimationPopView alloc] initWithCustomView:baseView popStyle:ZJAnimationPopStyleShakeFromLeft dismissStyle:ZJAnimationDismissStyleDropToRight];
    //显示时点击背景是否移除弹框
    popView.isClickBGDismiss = YES;
    [popView pop];
}
    
-(void)createUIWithTip:(TipType)tiptype andRow:(NSInteger)row{
    NSString *tipStr;
    if (tiptype == tipTypeOfCancelFavorite) {
        tipStr = @"你确定要取消此收藏吗?";
    }else{
        tipStr = @"你确定要取消此订单吗?";
    }
    
    UILabel *tipLab = [[UILabel alloc]init];
    [baseView addSubview:tipLab];
    tipLab.textAlignment = NSTextAlignmentCenter;
    tipLab.text = tipStr;
    tipLab.textColor = [UIColor colorWithHexString:@"#333333"];
    
    ECUButton *sureBtn = [ECUButton buttonWithType:UIButtonTypeCustom];
    [baseView addSubview:sureBtn];
    [sureBtn setTitle:@"确定" forState:0];
    sureBtn.backgroundColor = [UIColor colorWithHexString:@"#FF6701"];
    sureBtn.layer.masksToBounds = YES;
    sureBtn.layer.cornerRadius = 3.f;
    sureBtn.tag = row;
    [sureBtn addTarget:self action:@selector(sureBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    ECUButton *cancelBtn = [ECUButton buttonWithType:UIButtonTypeCustom];
    [baseView addSubview:cancelBtn];
    [cancelBtn setTitle:@"取消" forState:0];
    [cancelBtn setTitleColor:[UIColor colorWithHexString:@"#FF6700"] forState:0];
    [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(baseView.mas_centerX);
        make.top.equalTo(topImageView.mas_bottom).offset(kProportion_Height(90));
        make.width.equalTo(baseView.mas_width);
        make.height.equalTo(@18);
    }];
    
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(baseView.mas_centerX);
        make.bottom.equalTo(baseView.mas_bottom).offset(-kProportion_Height(150));
        make.width.equalTo(@(kProportion_Width(540)));
        make.height.equalTo(sureBtn.mas_width).multipliedBy(114.f/540.f);
    }];
    
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(baseView.mas_centerX);
        make.bottom.equalTo(baseView.mas_bottom).offset(-kProportion_Width(50));
        make.height.equalTo(@20);
        make.width.equalTo(@100);
    }];
}

/*
 确定按钮被点击  row 为点击某行
 */
-(void)sureBtnClick:(ECUButton *)btn{
    if (self.delegate && [self.delegate respondsToSelector:@selector(tipCustomViewOfSureBtnClickWithRow:)]) {
        [self.delegate tipCustomViewOfSureBtnClickWithRow:btn.tag];
        [popView dismiss];
    }
}

/*
 取消按钮被点击
 */
-(void)cancelBtnClick{
    [popView dismiss];
}




@end
